package com.wang.experiment.experiment3.booksystem;

import com.sun.org.apache.xml.internal.security.Init;

import javax.swing.*;
import java.awt.*;

/**
 * @author wr
 * @date 2021/10/26 22:13
 */
public class SummaryDialog extends JDialog {
    private final String summary;

    public SummaryDialog(Frame owner, String summary) {
        super(owner, "摘要", true);
        this.summary = summary;
        init();
    }

    private void init() {
        Rectangle parentBounds = getParent().getBounds();
        setBounds(parentBounds.x + parentBounds.width / 4,
                parentBounds.y + parentBounds.height / 4,
                parentBounds.width / 2,
                parentBounds.height / 2);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setLayout(new BorderLayout());

        //editor
        JTextArea summaryArea = new JTextArea(summary, 10, 20);
        summaryArea.setLineWrap(true);
        summaryArea.setEditable(false);
        add(summaryArea, BorderLayout.CENTER);

        //btn
        JPanel btnPanel = new JPanel();
        JButton btn = new JButton("确定");
        btn.addActionListener(e -> dispose());
        btnPanel.add(btn);
        add(btnPanel,BorderLayout.SOUTH);

        setVisible(true);
    }
}
